﻿using System;
using System.Configuration;
using System.Diagnostics;

namespace GenerateDataBaseLibrary
{
    class ExplotationTier 
    { 
        public static void CreateConfiguration()
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            SqlCredentialSection credentialSection = new SqlCredentialSection();
            credentialSection.SqlCredential = new SqlCredentialElement { UserName = "user", Password = "sa" };



            ParametersStorageSection section = new ParametersStorageSection();
            section.FileStorage = @"D:\temp\filestorage.txt";
            section.CfgFileStorage = @"C:\Users\Administrator\documents\visual studio 2010\Projects\GenerateDataBaseLibrary\GenerateDataBaseLibrary\bin\Debug\GenerateDataBaseLibrary.exe";
            section.Separator = ';';

            config.Sections.Add("credentialsection",credentialSection);
            config.Sections.Add("storageparameterssection", section);

            credentialSection.SectionInformation.ForceSave = true;
            section.SectionInformation.ForceSave = true;

            config.Save(ConfigurationSaveMode.Full);
            Debug.Print("Done");
        }

        public static T LoadConfiguration<T>(string configurationName) where T:ConfigurationSection
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) as Configuration;
            T section = (T)config.GetSection(configurationName);
            return section;
        }

    }
}
 

   

